appModule.controller("TerminalsController", ['$rootScope', '$scope', '$ionicActionSheet', '$ionicPopup', 'terminalService', function ($rootScope, $scope, $ionicActionSheet, $ionicPopup, terminalService) {
    $rootScope.sessions = [];
    $rootScope.$on("openTerminal", function(event, sessionConfig) {
        var sshSession = new SSHSession(sessionConfig);
        $(".terminal").hide();
        var terminalDiv = $("<div></div>").addClass("terminal").addClass("selectable").attr("id", sshSession.id).appendTo($("#terminals"));
        terminalService.openTerminal(terminalDiv, sshSession);
    });

    $rootScope.$on("closeTerminal", function(event, session) {
        $ionicPopup.confirm({
            title: "确定关闭连接" + session.name + "吗?"
        }).then(function(res) {
            terminalService.removeSession(session);
        });
    });

    $rootScope.$on("changeTerminal", function(event, session) {
        $(".terminal").hide();
        $("#" + session.id).show();
    });

    /*$ionicActionSheet.show({
        buttons: [
            { text: '<b>Share</b> This<a href="#">x</a>' },
            { text: 'Move' }
        ],
        destructiveText: 'Delete',
        titleText: '切换终端',
        cancelText: '取消',
        cancel: function() {
            // add cancel code..
        },
        buttonClicked: function(index) {
            return true;
        }
    });*/
}]);